<template>
  <div class="child2">
    <h1>子组件2</h1>
    <div>电脑: {{ computer }}</div>
    <div>接受的玩具: {{ toy }}</div>
  </div>
</template>

<script setup lang="ts" name="Child2">
import emitter from '@/utils/emitter';
import { onUnmounted, ref } from 'vue';

let toy = ref("")

const computer = ref('联想');

emitter.on('send-toy', (value: unknown) => {
  toy.value = value as string;
})

onUnmounted(() => {
  emitter.off('send-toy');
});


</script>